package demo;
import ioc.MiniApplicationContext;
public class Starter {
    public static void main(String[] args) throws Exception {
        System.out.println("=== 开始测试迷你IOC容器 ===");

        // 1. 创建IOC容器
        MiniApplicationContext ctx = new MiniApplicationContext(AppConfig.class);
        System.out.println("容器创建成功！");

        // 2. 显示所有注册的Bean
        System.out.println("已注册Bean数量: " + ctx.getBeanCount());

        // 3. 获取并使用Bean
        UserService userService = ctx.getBean(UserService.class);
        System.out.print("获取UserService: ");
        userService.hello();

        // 4. 按名称获取Bean（使用getBean(String)然后强制转换）
        UserDao userDao = ctx.getBean("userDao");
        System.out.println("获取UserDao: " + userDao.getClass().getSimpleName());

        // 5. 验证单例
        UserService anotherInstance = ctx.getBean(UserService.class);
        System.out.println("单例验证: " + (userService == anotherInstance ? "是同一个实例" : "不是同一个实例"));

        System.out.println("=== 测试完成！IOC容器工作正常 ===");
    }
}